#include <functional>
#include <memory>
#include <thread>
#include "rclcpp/rclcpp.hpp"

class TestSetParam : public rclcpp::Node
{
private:
    rclcpp::TimerBase::SharedPtr timer_;
    rclcpp::TimerBase::SharedPtr timer2_;
    std::vector<double> test_param;

public:
    TestSetParam();
    ~TestSetParam();

    void set_param()
    {
        // this->timer_->cancel();

        this->set_parameters(std::vector<rclcpp::Parameter>{
            rclcpp::Parameter("test.param", std::vector<double>{1.1, 4.4})});

        RCLCPP_INFO(this->get_logger(), "set param finished");
    }

    void get_param()
    {
        test_param = this->get_parameter("test.param").as_double_array();

        RCLCPP_INFO(this->get_logger(), "test_param is %lf  %lf", test_param[0], test_param[1]);
    }
};

TestSetParam::TestSetParam() : Node("test_set_param")
{
    this->declare_parameter("test.param", std::vector<double>{0.0, 0.0});

    this->timer_ = this->create_wall_timer(std::chrono::milliseconds(500), std::bind(&TestSetParam::get_param, this));
    this->timer2_ = this->create_wall_timer(std::chrono::milliseconds(5000), std::bind(&TestSetParam::set_param, this));
}

TestSetParam::~TestSetParam()
{
}

int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);

    auto node = std::make_shared<TestSetParam>();

    rclcpp::spin(node);

    rclcpp::shutdown();
    return 0;
}